using Scenario_Editor.Addin.Traffic;
using System;
using System.Windows.Forms;

namespace street.Controls
{
    public partial class TrafficUI : UserControl
    {
        #region Private Fields

        private bool isForCrossroad = false;

        #endregion Private Fields

        #region Public Constructors

        public TrafficUI()
        {
            InitializeComponent();
        }

        #endregion Public Constructors

        #region Public Properties

        public bool IsForCrossroads
        {
            get
            {
                return isForCrossroad;
            }
            set
            {
                isForCrossroad = value;
                this.checkBox_IsPriorityStreet.Visible = isForCrossroad;
                this.checkBox_TrafficLeft.Visible = !isForCrossroad;
                this.checkBox_TrafficRight.Visible = !isForCrossroad;
            }
        }

        #endregion Public Properties

        #region Public Methods

        public WR2Traffic GetTrafficData()
        {
            return new WR2Traffic(//true,
                   this.checkBox_TrafficLeft.Checked,
                   this.checkBox_TrafficRight.Checked,
                   (int)this.nud_traffic_lanes.Value,
                   (float)this.nud_traffic_Offset1.Value,
                   (float)this.nud_traffic_Offset2.Value,
                   (float)this.nud_traffic_Speed.Value,
                   (int)this.nud_traffic_lanes.Value,
                   (float)this.nud_traffic_Offset1.Value,
                   (float)this.nud_traffic_Offset2.Value,
                   (float)this.nud_traffic_Speed.Value,
                    Convert.ToInt32(this.checkBox_IsPriorityStreet.Enabled));
        }

        public void SetTrafficData(WR2Traffic value)
        {
            WR2Traffic traffice = value;
            this.checkBox_TrafficLeft.Checked = traffice.hasLaneLeft;
            this.checkBox_TrafficRight.Checked = traffice.hasLaneRight;
            if (traffice.LaneLeft.numberofLanes == 2 || traffice.LaneLeft.numberofLanes == 1)
                this.nud_traffic_lanes.Value = (decimal)traffice.LaneLeft.numberofLanes;
            this.nud_traffic_Offset1.Value = (decimal)traffice.LaneLeft.Offset1;
            this.nud_traffic_Offset2.Value = (decimal)traffice.LaneLeft.Offset2;
            if ((decimal)traffice.speedLeftLane <= this.nud_traffic_Speed.Maximum && (decimal)traffice.speedLeftLane >= this.nud_traffic_Speed.Minimum)
                this.nud_traffic_Speed.Value = (decimal)traffice.speedLeftLane;
        }

        #endregion Public Methods

        #region Private Methods

        private void Property_ValueChanged(object sender, EventArgs e)
        {
            streetTool.hasPropertiesChanged = true;
        }

        #endregion Private Methods
    }
}